// releasePage/pages/reviewReason/reviewReason.js
import throttle from '../../../utils/throttle.js';
import Http from '../../../utils/http.js';
const http = new Http();
const app = getApp();
Page({
    /**
     * 页面的初始数据
     */
    data: {
        id: '',
        type: '',
        description: '',
        placeholder: '请输入你的理由',
        fromWhere: '', //fromWhere  00--打卡拒绝    01--其他删除  02--意见通过    03--意见拒绝
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        if (app.globalData.isIpx) {
            this.setData({
                ipxBottom: 34,
            });
        }
        this.setData({
            id: options.id,
            type: options.type,
            fromWhere: options.fromWhere,
        });
        if (options.fromWhere == '00' || options.fromWhere == '03') {
            if (options.fromWhere == '03') {
                this.setData({
                    placeholder: '输入拒绝原因（选填）',
                });
            }
            wx.setNavigationBarTitle({
                title: '拒绝理由',
            });
        }
        if (options.fromWhere == '01') {
            wx.setNavigationBarTitle({
                title: '删除理由',
            });
        }
        if (options.fromWhere == '02') {
            this.setData({
                placeholder: '输入采纳原因（选填）',
            });
            wx.setNavigationBarTitle({
                title: '采纳原因',
            });
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {},

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {},
    back() {
        wx.navigateBack({
            detal: 1,
        });
    },
    description(e) {
        this.setData({
            description: e.detail.value,
        });
        app.numLimitTip(e.detail.value.length, 200);
    },
    submit: throttle(
        function (e) {
            let _that = this;
            if (_that.data.fromWhere == '00' || _that.data.fromWhere == '01') {
                let data = {
                    authId: app.globalData.authId,
                    id: _that.data.id,
                    type: _that.data.type,
                    delflg: '01',
                    refusereason: _that.data.description,
                };
                http.getRequest(`cjMap/doVerify`, data).then((res) => {
                    if (res.status == 0) {
                        wx.showToast({
                            title: '提交成功',
                            icon: 'success',
                            duration: 2000,
                        });
                        let pages = getCurrentPages(); //当前页面栈
                        let prevPage1 = pages[pages.length - 3];
                        if (_that.data.type == '05') {
                            prevPage1.refreshCheckIn();
                        } else if (_that.data.type == '10') {
                            wx.removeStorageSync('refreshMapPointId'); //刷新地图标记点
                            app.globalData.expRefresh = true;
                            app.globalData.indexExpRefresh = true;
                            prevPage1.refreshExperience();
                        } else {
                            prevPage1.refreshInput();
                        }
                    }
                });
                setTimeout(function () {
                    wx.navigateBack({
                        delta: 2, // 返回上一级页面。
                    });
                }, 2000);
            } else {
                let data = {
                    id: _that.data.id,
                    verifyflg: _that.data.fromWhere == '02' ? '01' : '02',
                    reason: _that.data.description,
                };
                http.postRequest(
                    `cjMap/handleSysProposal?authId=${app.globalData.authId}`,
                    data
                ).then((res) => {
                    if (res.status == 0) {
                        wx.showToast({
                            title: '提交成功',
                            icon: 'success',
                            duration: 2000,
                        });
                        let pages = getCurrentPages(); //当前页面栈
                        let prevPage = pages[pages.length - 2];
                        prevPage.refreshNewsList();
                    }
                });
                setTimeout(function () {
                    wx.navigateBack({
                        delta: 1, // 返回上一级页面。
                    });
                }, 2000);
            }
        },
        4000,
        {
            trailing: false,
        }
    ),
});
